package com.bk.bookviews.util;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.bk.bookviews.common.Pagination;
import com.bk.bookviews.enums.MsgEnum;

import java.util.List;

public class PageUtils {
    public static long totalPages(List list){return new PageInfo(list).getTotal(); }

    public static Pagination getPagination(Pagination pagination){
        try {
            //获取得到的数据
            Page<?> page = (Page<?>)pagination.getData();
            //设置分页信息
            pagination.setPageInfo(pagination.new PageInfo(page.getTotal(),page.getPageNum(),page.getPageSize()));
            pagination.setCode(MsgEnum.SUCCESS.getCode());
            return pagination;
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }

}
